﻿using System;
using System.Web.UI;
using Kiiro.Common.Utility;
using Kiiro.SiteDefinition.MasterPage;

namespace Kiiro.SiteDefinition.ApplicationPages
{
    public partial class KiiroAccessDenied : Microsoft.SharePoint.ApplicationPages.AccessDeniedPage
    {
        /// <summary>
        /// Process Access Denied using default SharePoint behavior
        /// MUST override void OnLoad because using void Page_Load cause an infinite recursive loop.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad ( EventArgs e )
        {
            // set page using default SharePoint template
            base.OnLoad ( e );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender ( EventArgs e )
        {
            KiiroMaster master = ( KiiroMaster ) Master;

            if (master.Base.CurrentUser.Login == Constants.Security.AD_AUTH_USERS_DOMAIN_GROUP_NAME)
            {
                master.Footer.Visible = false;
                foreach ( Control control in master.V2Header.AccessDeniedControlsToHide )
                    control.Visible = false;
            }

            string requestedUrl = Request.Path.ToString ( ).Remove ( Request.Path.ToString ( ).LastIndexOf ( "/" ) );
            // override link back to SharePoint AccessDenied Page
            this.HLinkLoginAsAnother.NavigateUrl = "javascript:LoginAsAnother('" + requestedUrl + "\u002faccessdenied.aspx?loginasanotheruser=true', 1)";

            // hide link to request acces page as it does not exist on our site currently
            this.HLinkRequestAccess.Visible = false;

            base.OnPreRender ( e );
        }
    }
}

/*************************************************************************
 * 
 * $Log: /Internal Projects/Kiiro/Kiiro.SiteDefinition/12/TEMPLATE/FEATURES/Kiiro.ApplicationPages/ApplicationPages/KiiroAccessDenied.aspx.cs $
 * 
 * 9     1/08/10 11:30a Camerons
 * 
 * 8     12/21/09 5:06p Camerons
 * 
 * 7     12/18/09 11:34a Camerons
 * 
 * 6     18/11/09 12:24p Camerons
 * 
 * 5     28/10/09 10:32p Camerons
 * 
 * 4     3/09/09 11:16a Shafia
 * OnPreRender we get the requested url for the current kiiro site and set
 * the link to it 
 * 
 * 3     17/08/09 11:07a Camerons
 * Added check-in comments section
 * 
 ************************************************************************/